﻿using System.Collections.Generic;
using System.Reflection;
using SimpleServiceBus.Bus;
using SimpleServiceBus.Configuration;
using SimpleServiceBus.Endpoint;
using SimpleServiceBus.Endpoint.Metadata;

namespace SimpleServiceBus.Tests.Stubs
{
    public class TestEndpoint : MessagingEndpoint
    {
        public List<Assembly> RegisteredMessageHandlerAssemblies { get; set; }
        
        public EndpointServiceManager PublicLocalServices
        {
            get { return LocalServices; }
        }

        public static TestEndpoint Create(/*params object[] localServices*/)
        {
            return ConfigureEndpoint(/*localServices*/).Endpoint as TestEndpoint;
        }

        public static IEndpointBuilder ConfigureEndpoint(/*params object[] localServices*/)
        {
            var builder = new EndpointBuilder<TestEndpoint,TestTransport>();
            var ep = builder.CreateEndpoint();

            builder.RegisterService<IMessageBus, TestBus>();
           

            var metadata = new EndpointDescription
                               {
                                   EndpointID = "MyEndpointID",
                                   Name = "MyEndpointName",
                                   ReturnAddress = "Test"
                               };

            ep.Metadata = metadata;

            builder.MessageHandlers.RegisterMessageHandlerAssembly(typeof (TestEndpoint).Assembly);

            return builder;
        }
    }
}